package proxyskeleton;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;

public class ClientCallbackHandler implements CallbackHandler{
	String userid, password;
	
	public ClientCallbackHandler(String userid, String password) {
		super();
		this.userid = userid;
		this.password = password;
	}

	@Override
	public void handle(Callback[] callbacks) throws IOException,
			UnsupportedCallbackException {
		
		for (int i = 0; i < callbacks.length; i++) {
		    if (callbacks[i] instanceof NameCallback) {
		 		NameCallback nc = (NameCallback)callbacks[i];
		 		nc.setName(userid);
	 	    }
		    else if (callbacks[i] instanceof PasswordCallback) {
		 		PasswordCallback pc = (PasswordCallback)callbacks[i];
		 		pc.setPassword(password.toCharArray());
	  
	 	    }    
		}
		
	}

}
